package com.geo.result.controller;

import com.sino.common.core.utils.poi.ExcelUtil;
import com.sino.common.core.web.controller.BaseController;
import com.sino.common.core.web.domain.AjaxResult;
import com.sino.common.core.web.page.TableDataInfo;
import com.sino.common.log.annotation.Log;
import com.sino.common.log.enums.BusinessType;
import com.geo.result.domain.TestDemo;
import com.geo.result.service.ITestDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 测试样例Controller
 * 
 * @author tangyongbo
 * @date 2020-07-03
 */
@RestController
@RequestMapping("/demo")
public class TestDemoController extends BaseController
{
    @Autowired
    private ITestDemoService testDemoService;

    /**
     * 查询测试样例列表
     */
    @PreAuthorize("@ss.hasPermi('result:demo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestDemo testDemo)
    {
        startPage();
        List<TestDemo> list = testDemoService.selectTestDemoList(testDemo);
        return getDataTable(list);
    }

    /**
     * 导出测试样例列表
     */
    @PreAuthorize("@ss.hasPermi('result:demo:export')")
    @Log(title = "测试样例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody TestDemo testDemo) throws IOException
    {
        List<TestDemo> list = testDemoService.selectTestDemoList(testDemo);
        ExcelUtil<TestDemo> util = new ExcelUtil<TestDemo>(TestDemo.class);
        util.exportExcel(response, list, "demo");
    }

    /**
     * 获取测试样例详细信息
     */
    @PreAuthorize("@ss.hasPermi('result:demo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(testDemoService.selectTestDemoById(id));
    }

    /**
     * 新增测试样例
     */
    @PreAuthorize("@ss.hasPermi('result:demo:add')")
    @Log(title = "测试样例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestDemo testDemo)
    {
        return toAjax(testDemoService.insertTestDemo(testDemo));
    }

    /**
     * 修改测试样例
     */
    @PreAuthorize("@ss.hasPermi('result:demo:edit')")
    @Log(title = "测试样例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestDemo testDemo)
    {
        return toAjax(testDemoService.updateTestDemo(testDemo));
    }

    /**
     * 删除测试样例
     */
    @PreAuthorize("@ss.hasPermi('result:demo:remove')")
    @Log(title = "测试样例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(testDemoService.deleteTestDemoByIds(ids));
    }
}
